package com.atguigu.cloud.resp;

import lombok.Getter;

import java.util.Arrays;

/**
 * @author yuanx
 * @date 2024/3/3 23:05
 */
@Getter
public enum ReturnCodeEnum {

    RC200("200","200成功"),
    RC999("999","999错误"),
    RC404("404","404错误"),
    RC500("500","500错误");
    private final String code;
    private final String msg;



    ReturnCodeEnum(String code, String msg) {
        this.code=code;
        this.msg=msg;
    }
    private static ReturnCodeEnum getReturnCodeEnum(String code){
        for (ReturnCodeEnum returnCodeEnum : ReturnCodeEnum.values()) {
            if (returnCodeEnum.getCode().equalsIgnoreCase(code)){
                return  returnCodeEnum;
            }
        }
        return null;
    }

    private static ReturnCodeEnum getReturnCodeEnumV2(String code){
          return Arrays.stream(ReturnCodeEnum.values()).filter(a -> a.getCode().equalsIgnoreCase(code)).findFirst().orElse(null);

    }

    public static void main(String[] args) {
        System.out.println(ReturnCodeEnum.getReturnCodeEnumV2("200"));
        System.out.println(ReturnCodeEnum.getReturnCodeEnumV2("200").getCode());
        System.out.println(ReturnCodeEnum.getReturnCodeEnumV2("200").msg);
    }
}
